﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
/// <summary>
/// Summary description for CommentDAL
/// </summary>
public class CommentDAL
{
    public DataAccess db;
	public CommentDAL()
	{
        db = new DataAccess();
    }
    public DataTable getAllComment() 
    {
        return db.executeSelect("SL_Comment");
    }
    public int Insert_UpdateComment(Comment comment) 
    {
        SqlParameter[] paralist = new SqlParameter[6];
        paralist[0] = db.AddParameter("comment_id", comment.Comment_id, SqlDbType.Int, null);
        paralist[1] = db.AddParameter("article_id", comment.Article_id, SqlDbType.Int, null);
        paralist[2] = db.AddParameter("comment_name", comment.Comment_name, SqlDbType.NVarChar, 50);
        paralist[3] = db.AddParameter("comment_des",comment.Comment_des,SqlDbType.Text,null);
        paralist[4] = db.AddParameter("email", comment.Email, SqlDbType.NVarChar, 50);
        paralist[5] = db.AddParameter("status", comment.Status, SqlDbType.Bit, null);
        return db.executeUpdate("IS_Comment", paralist);
    }
    public DataTable getCommentByID(int comment_id)
    {
        SqlParameter[] paraList = new SqlParameter[3];
        paraList[0] = db.AddParameter("comment_id", comment_id, SqlDbType.Int, null);
        paraList[1] = db.AddParameter("article_id", null, SqlDbType.Int, null);
        paraList[2] = db.AddParameter("email", null, SqlDbType.NVarChar, 50);
        return db.executeSelect("SL_Comment", paraList);
    }
    public DataTable getCommentByArticle(int article_id) 
    {
        SqlParameter[] paraList = new SqlParameter[3];
        paraList[0] = db.AddParameter("comment_id", null, SqlDbType.Int, null);
        paraList[1] = db.AddParameter("article_id", article_id, SqlDbType.Int, null);
        paraList[2] = db.AddParameter("email", null, SqlDbType.NVarChar, 50);
        return db.executeSelect("SL_Comment", paraList);
    }
    public DataTable getCommentByEmail(string email)
    {
        SqlParameter[] paraList = new SqlParameter[3];
        paraList[0] = db.AddParameter("comment_id", null, SqlDbType.Int, null);
        paraList[1] = db.AddParameter("article_id", null, SqlDbType.Int, null);
        paraList[2] = db.AddParameter("email", email, SqlDbType.NVarChar, 50);
        return db.executeSelect("SL_Comment", paraList);
    }
    public DataTable getEmailByUserName(string username) 
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = db.AddParameter("user_name", username, SqlDbType.NVarChar, 50);
        return db.executeSelect("SL_EmailbyUserName", paraList);
    }
    public DataTable getCommentIsTrue(int article_id) 
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = db.AddParameter("article_id", article_id, SqlDbType.Int, null);
        return db.executeSelect("SL_CommentIsTrue", paraList);
    }
}